package 集合;

import java.util.ArrayList;

public class 存储学生对象并遍历 {
    public static void main(String[] args) {

        ArrayList<student> array=new ArrayList<student>();
        //创建学生对象
        student s1=new student("姜恒星",18);
        student s2=new student("张三",20);
        student s3=new student("李四",22);
        //添加学生到集合中
        array.add(s1);
        array.add(s2);
        array.add(s3);
        //遍历集合
        for (int i=0;i<array.size();i++){
            student s=array.get(i);
            System.out.println(s.getName()+","+s.getAge());
        }
    }
}
